<?
require_once($r."_engine/c_account.php");
require_once($r."_engine/c_session.php");
require_once($r."_engine/functions.php");

define("LOGIN_INCORRECT", 1);
define("LOGIN_NOT_ACTIVATED", 2);
define("LOGIN_ACCOUNT_EXIPIRED", 3);

if (@$action == "login")
{
	$account = new CAccount();
	if (!$account->LoadByEmail($f_login_email) || 
		$f_login_password != $account->data["password"]) 
	{
		$status = LOGIN_INCORRECT;
	}
	else 
	{
		if (!$account->data["activated"])
		{
			$status = LOGIN_NOT_ACTIVATED;
		}
		else
		{
			if ($account->data["expire"] < gmt_time())
			{
				$status = LOGIN_ACCOUNT_EXIPIRED;
			}
			else 
			{
				$account->Update(array(
					"last_login"	=> $account->data["current_login"],
					"current_login"	=> gmt_time(),
				));

				$g_session->Set($account->id, $account->data["password"], isset($f_remember));
				
				generate_html_redirect(@$ref ? $ref : "dashboard.php");
			}
		}
	}
}
?>
